package com.exam.hellohass.utils;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.provider.DocumentsContract.Document;

public class JsoupThread {

	static String content="";
	static String divcontent="";
	
	static String divcontent_1="";
	
	static String content_1="";
	static String divcontent_2="";
	
	static String divcontent_3="";
	
	public static String getImage(String url) throws IOException {
		// TODO Auto-generated method stub
		String abs = url;
		String imgUrl1="";
		
			org.jsoup.nodes.Document doc = Jsoup.connect(url).data("jquery", "java")
					.userAgent("hellohass").cookie("auth", "token").timeout(50000)
					.get();
			
			content = doc.toString();
			
			org.jsoup.nodes.Document doc1 = Jsoup.parse(content);
//			Elements divs = doc1.getElementsByClass("ywtop2");
			Elements divs = doc1.getElementsByClass("pic");
			divcontent = divs.toString();
			
			org.jsoup.nodes.Document doc2 = Jsoup.parse(divcontent,abs);
			Elements pngs = doc2.getElementsByTag("img");
			for (Element element : pngs) {
				imgUrl1 = element.attr("abs:src");
			}
		return imgUrl1;
	}
	
	public static String getImageUrl(String url) throws IOException {
		// TODO Auto-generated method stub
		String abs = url;
		String imgUrl="";
		
			org.jsoup.nodes.Document doc = Jsoup.connect(url).data("jquery", "java")
					.userAgent("hellohass").cookie("auth", "token").timeout(50000)
					.get();
			
			content_1 = doc.toString();
			
			org.jsoup.nodes.Document doc1 = Jsoup.parse(content_1);
//			Elements divs = doc1.getElementsByClass("ywtop2");
			Elements divs = doc1.getElementsByClass("pic");
			divcontent_2 = divs.toString();
			
			org.jsoup.nodes.Document doc2 = Jsoup.parse(divcontent_2,abs);
			Elements pngs = doc2.select("a");
			for (Element element : pngs) {
				imgUrl = element.attr("abs:href");
			}
		return imgUrl;
	}

}
